-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added d1 export --local
support
#6073
Conversation
🦋 Changeset detectedLatest commit: 6f94501 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9691836885/npm-package-wrangler-6073 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6073/npm-package-wrangler-6073 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9691836885/npm-package-wrangler-6073 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9691836885/npm-package-create-cloudflare-6073 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9691836885/npm-package-cloudflare-kv-asset-handler-6073 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9691836885/npm-package-miniflare-6073 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9691836885/npm-package-cloudflare-pages-shared-6073 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9691836885/npm-package-cloudflare-vitest-pool-workers-6073 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
3025559
to
b2ada25
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my own education, does this PR mean that PRAGMA miniflare_d1_export(?,?,?);
is part of our public API now? I don't think we want it to be so. How do we prevent people from writing that in their own queries?
} | ||
} | ||
|
||
if (!noSchema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter that this query appears first in shell.c.in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it? This is supposed to match up with https://github.com/sqlite/sqlite/blob/105c20648e1b05839fd0638686b95f2e3998abcb/src/shell.c.in#L8472, i.e. directly after run_schema_dump_query
(which dumps schema & data), it checks SHFLG_DumpDataOnly)
is not set before exporting all ('index','trigger','view')
rows of sqlite_schema
Have I got that wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you're correct.
runWrangler("d1 export db --local --output /tmp/test.sql") | ||
).rejects.toThrowError( | ||
`Local imports/exports will be coming in a future version of Wrangler.` | ||
it("should handle local", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably add tests for the edge cases like quoted names adding the "IF NOT EXISTS" as well as properly quoting things like keywords.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have all these inside the D1 codebase, but see #6073 (comment) I think it makes sense for this file to live in a separate package with a whole suite of tests (as well as a test runner that runs native SQLite for comparison like the D1 suite does).
Imo that's a follow-up task. For the moment I'm just keeping the two implementations in sync manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it could be a follow-up task.
It's part of miniflare's implementation of D1, but not present anywhere else. It's not accessible from We could refactor Ideally, Miniflare would make it possible to do an end-run around the D1 shim and hit an object directly with an RPC call, but as far as I can find out that's not possible. |
This uses a new miniflare-only debug pragma `PRAGMA miniflare_d1_export` to trigger the dump as D1 provides no in-Worker API (which Miniflare uses) to generate exports.
b2ada25
to
6f94501
Compare
} | ||
} | ||
|
||
if (!noSchema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you're correct.
runWrangler("d1 export db --local --output /tmp/test.sql") | ||
).rejects.toThrowError( | ||
`Local imports/exports will be coming in a future version of Wrangler.` | ||
it("should handle local", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it could be a follow-up task.
This uses a new miniflare-only debug pragma
PRAGMA miniflare_d1_export
to trigger the dump as D1 provides no in-Worker API (which Miniflare uses) to generate exports.I'm open to other ways to implement this.
What this PR solves / how to test
Fixes limitation with the previous iteration of the export functionality. Previously, all
d1 export --local
commands would fail.Author has addressed the following
--local
doesn't work, it just emphasises--remote
(which still makes sense to be the default).